
/*
 *  Copyright (c) 2016. For Intelligent Group.
 *
 */

package com.intelligent.ispc.client.event;

import com.google.common.eventbus.Subscribe;
import com.intelligent.ispc.client.core.view.analysis.grr.GrrMainPanel;
import com.intelligent.ispc.client.core.view.analysis.report.YieldPanel;
import com.intelligent.ispc.client.core.view.analysis.spc.SpcMainPanel;
import com.intelligent.ispc.client.core.view.global.MainTopToolBar;
import com.intelligent.ispc.client.utils.ApplicationBeanUtils;
import com.intelligent.ispc.client.utils.UIConstant;

/**
 * Created by Lucien.Chen on 2016/11/2.
 */
public class ExportBtnListener {

    /**
     * Event subscribe method for setting export button.
     *
     * @param event ExportBtnEnabledEvent instance
     */
    @Subscribe
    public void setExportBtnEnabled(ExportBtnEnabledEvent event) {

        ApplicationBeanUtils.getBean(MainTopToolBar.class).setExportBtnEnabled(event.getKey(), event.isEnabled());
    }

    /**
     * Event subscribe method for setting export button.
     *
     * @param event ExportBtnClickEvent instance
     */
    @Subscribe
    public void clickExportBtn(ExportBtnClickEvent event) {
        try {
            if (event.getKey() == null) {
                return;
            }
            if (event.getKey().equals(UIConstant.MODULE_SPC)) {
                ApplicationBeanUtils.getBean(SpcMainPanel.class).showExportMenu(event.getInvoker());
            } else if (event.getKey().equals(UIConstant.MODULE_YIELD)) {
                ApplicationBeanUtils.getBean(YieldPanel.class).showExportMenu(event.getInvoker());
            } else if (event.getKey().equals(UIConstant.MODULE_GRR)) {
                ApplicationBeanUtils.getBean(GrrMainPanel.class).showExportMenu(event.getInvoker());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
